<?php
defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

pc_base::load_app_func('util','anjia');
pc_base::load_app_func('dboper','anjia');

class house {
    private $db;
    private $catid;
    function __construct() {
        $this->db = pc_base::load_model('anjia_content_model');
        $this->catid=6;
    }
    
    //添加房源
    public function add(){
        $addArray;        
        $addArray['regionId']=$regionId=$_POST['regionId'];
        $addArray['address']=$address=$_POST['address'];
        $addArray['title']=$title=$_POST['title'];
        $addArray['price']=$price=$_POST['price'];
        $addArray['houseLayout']=$houseLayout=$_POST['houseLayout'];
        $addArray['area']=$area=$_POST['area'];
        $addArray['unitprice']=$unitprice=$_POST['unitprice'];
        $addArray['orientation']=$orientation=$_POST['orientation'];
        $addArray['floor']=$floor=$_POST['floor'];
        $addArray['model']=$model=$_POST['model'];
        $addArray['elevator']=$elevator=$_POST['elevator'];
        $addArray['year']=$year=$_POST['year'];
        $addArray['sourceagencyId']=$sourceagencyId=$_POST['sourceagencyId'];
        $addArray['landlordId']=$landlordId=$_POST['landlordId'];
        $addArray['consumerId']=$consumerId=$_POST['consumerId'];
        $addArray['sellstate']=$sellstate=$_POST['sellstate'];
        $addArray['offsellReason']=$offsellReason=$_POST['offsellReason'];
        $addArray['selleragencyId']=$selleragencyId=$_POST['selleragencyId'];     
        $addArray['description']=$description=$_POST['description'];
        $md5code=$_POST['md5'];
        $checkResult=md5check($regionId.$address.$title.$price.$houseLayout
            .$area.$unitprice.$orientation.$floor.$model
            .$elevator.$year.$sourceagencyId.$landlordId.$consumerId.$sellstate
            .$offsellReason.$selleragencyId.$description    
            ,$md5code);
        if($checkResult)
        {
            $id=add($this->catid,$addArray,$this->db);
            $respjson;
            if(is_numeric($id)){
                $respjson='{
	            "errNo": 0,
	            "result":{
	            "organizationId":"'.$id.'"
	        }
	        }';
            }
            else{
                $respjson='{
	            "errNo": 1,
	            "result":
	           '.$id.'
	               
	        }';
            }
            echo $respjson;
        }
        else{
            $respjson='{
	            "errNo": 1,
	            "result":{
	            "error":"InternalError"
	        }
	        }';
            echo $respjson;
        }
    }
    //获取房源
    public function search(){
        $where;
        $where['id']=$id=$_POST['id'];
        $where['regionId']=$regionId=$_POST['regionId'];
        $where['address']=$address=$_POST['address'];
        $where['title']=$title=$_POST['title'];
        $where['price']=$price=$_POST['price'];
        $where['houseLayout']=$houseLayout=$_POST['houseLayout'];
        $where['area']=$area=$_POST['area'];
        $where['unitprice']=$unitprice=$_POST['unitprice'];
        $where['orientation']=$orientation=$_POST['orientation'];
        $where['floor']=$floor=$_POST['floor'];
        $where['model']=$model=$_POST['model'];
        $where['elevator']=$elevator=$_POST['elevator'];
        $where['year']=$year=$_POST['year'];
        $where['sourceagencyId']=$sourceagencyId=$_POST['sourceagencyId'];
        $where['landlordId']=$landlordId=$_POST['landlordId'];
        $where['consumerId']=$consumerId=$_POST['consumerId'];
        $where['sellstate']=$sellstate=$_POST['sellstate'];
        $where['offsellReason']=$offsellReason=$_POST['offsellReason'];
        $where['selleragencyId']=$selleragencyId=$_POST['selleragencyId'];
        $where['description']=$description=$_POST['description'];
        $md5code=$_POST['md5'];
        $pn=$_GET['pn'];
        $num=$_GET['num'];
        $checkResult=md5check($id.$organizationID.$parentOrganId.$pn.$num,$md5code);
        //组装查询条件
        removeEmptyArrayElement($where);
        $returndata='id,title,belongCompanyID';
        if($checkResult)
        {
            $resultarray=lists($this->catid,$where,$pn,$num,$this->db,$returndata);
            $respjson;
            
            $respjson='{
	            "errNo": 0,
	            "result":'.$resultarray.'
	        }';
            
            
            
            echo $respjson;
            
        }
        else{
            $respjson='{
	            "errNo": 1,
	            "result":{
	            "error":"InternalError"
	        }
	        }';
            echo $respjson;
        }
    }
    //修改机构
    public function update(){
        $organizationId=$_POST['organizationId'];
        $organizationName=$_POST['organizationName'];
        $parentOrganId=$_POST['parentOrganId'];
        $comments=$_POST['comments'];
        $md5code=$_POST['md5'];
        $checkResult=md5check($organizationId.$organizationName.$parentOrganId.$comments,$md5code);
        if($checkResult)
        {
            $updateArray=array("title"=>$organizationName,"belongCompanyID"=>$parentOrganId,"comments"=>$comments);
            $result=update($this->catid,$organizationId,$updateArray,$this->db);
            $respjson;
            if($result)
                $respjson='{
	            "errNo": 0,
	            "result":"更新成功"
	        }';
                else{
                    $respjson='{
	            "errNo": 0,
	            "result":"更新失败"
	        }';
                }
                echo $respjson;
        }
        else{
            $respjson='{
	            "errNo": 1,
	            "result":{
	            "error":"InternalError"
	        }
	        }';
            echo $respjson;
        }
        
    }
    
    //删除机构
    public function delete(){
        $organizationId=$_GET['organizationId'];
        $md5code=$_GET['md5'];
        $checkResult=md5check($organizationId,$md5code);
        if($checkResult)
        {
            $result=delete($this->catid,$organizationId,$this->db);
            $respjson;
            if($result)
                $respjson='{
	            "errNo": 0,
	            "result":"删除成功"
	        }';
                else{
                    $respjson='{
	            "errNo": 0,
	            "result":"删除失败"
	        }';
                }
                echo $respjson;
        }
        else{
            $respjson='{
	            "errNo": 1,
	            "result":{
	            "error":"internalError"
	        }
	        }';
            echo $respjson;
        }
        
    }
    
    
}
?>